<?php
$code = $_GET['code'];
$name = $_GET['name'];
    $api = "https://api.q.qq.com/sns/jscode2session?appid=小程序ID&secret=小程序密钥&js_code=".$code."&grant_type=authorization_code";
    $result = curl_get($api);//请求拼接好的url
    $wxResult = json_decode($result, true);
    $openid = $wxResult['openid'];
    echo $openid;
//php请求网络的方法
function curl_get($url, &$httpCode = 0) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    //不做证书校验,部署在linux环境下请改为true
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
    $file_contents = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    return $file_contents;
}
?>